package com.alipay.app.groupmeal.standard.mqtt;


import com.tencent.iot.explorer.device.java.mqtt.TXMqttRequest;
import com.tencent.iot.hub.device.java.core.common.Status;
import com.tencent.iot.hub.device.java.core.mqtt.TXMqttActionCallBack;

import org.eclipse.paho.client.mqttv3.IMqttToken;
import org.eclipse.paho.client.mqttv3.MqttMessage;

/**
 * 实现TXMqttActionCallBack回调接口
 */
public class SelfMqttActionCallBack extends TXMqttActionCallBack {

    @Override
    public void onConnectCompleted(Status status, boolean reconnect, Object userContext, String msg, Throwable cause) {
        String userContextInfo = "";
        if (userContext instanceof TXMqttRequest) {
            userContextInfo = userContext.toString();
        }
//            String logInfo = String.format("onConnectCompleted, status[%s], reconnect[%b], userContext[%s], msg[%s]",
//                    status.name(), reconnect, userContextInfo, msg);
//            mParent.printLogInfo(TAG, logInfo, mLogInfoText, TXLog.LEVEL_INFO);
    }

    @Override
    public void onConnectionLost(Throwable cause) {
        String logInfo = String.format("onConnectionLost, cause[%s]", cause.toString());
        cause.printStackTrace();
//            mParent.printLogInfo(TAG, logInfo, mLogInfoText, TXLog.LEVEL_INFO);
    }

    @Override
    public void onDisconnectCompleted(Status status, Object userContext, String msg, Throwable cause) {
        String userContextInfo = "";
        if (userContext instanceof TXMqttRequest) {
            userContextInfo = userContext.toString();
        }
//            String logInfo = String.format("onDisconnectCompleted, status[%s], userContext[%s], msg[%s]", status.name(), userContextInfo, msg);
//            mParent.printLogInfo(TAG, logInfo, mLogInfoText, TXLog.LEVEL_INFO);
    }

    @Override
    public void onPublishCompleted(Status status, IMqttToken token, Object userContext, String errMsg, Throwable cause) {
        String userContextInfo = "";
        if (userContext instanceof TXMqttRequest) {
            userContextInfo = userContext.toString();
        }
//            String logInfo = String.format("onPublishCompleted, status[%s], topics[%s],  userContext[%s], errMsg[%s]",
//                    status.name(), Arrays.toString(token.getTopics()), userContextInfo, errMsg);
//            mParent.printLogInfo(TAG, logInfo, mLogInfoText);
    }

    @Override
    public void onSubscribeCompleted(Status status, IMqttToken asyncActionToken, Object userContext, String errMsg, Throwable cause) {
        String userContextInfo = "";
        if (userContext instanceof TXMqttRequest) {
            userContextInfo = userContext.toString();
        }
//            String logInfo = String.format("onSubscribeCompleted, status[%s], topics[%s], userContext[%s], errMsg[%s]",
//                    status.name(), Arrays.toString(asyncActionToken.getTopics()), userContextInfo, errMsg);
//            if (Status.ERROR == status) {
//                mParent.printLogInfo(TAG, logInfo, mLogInfoText, TXLog.LEVEL_ERROR);
//            } else {
//                mParent.printLogInfo(TAG, logInfo, mLogInfoText);
//            }
    }

    @Override
    public void onUnSubscribeCompleted(Status status, IMqttToken asyncActionToken, Object userContext, String errMsg, Throwable cause) {
        String userContextInfo = "";
        if (userContext instanceof TXMqttRequest) {
            userContextInfo = userContext.toString();
        }
//            String logInfo = String.format("onUnSubscribeCompleted, status[%s], topics[%s], userContext[%s], errMsg[%s]",
//                    status.name(), Arrays.toString(asyncActionToken.getTopics()), userContextInfo, errMsg);
//            mParent.printLogInfo(TAG, logInfo, mLogInfoText);
    }

    @Override
    public void onMessageReceived(final String topic, final MqttMessage message) {
//            String logInfo = String.format("receive command, topic[%s], message[%s]", topic, message.toString());
//            mParent.printLogInfo(TAG, logInfo, mLogInfoText);
    }
}